package com.CloudDream.Command.Admin;

import com.CloudDream.MoonCake;
import com.CloudDream.Util.RecipeUtil;
import com.handy.lib.command.IHandyCommandEvent;
import com.handy.lib.util.BaseUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;

public class ReloadCommand implements IHandyCommandEvent {

    private MoonCake instance = MoonCake.getInstance();

    @Override
    public String command() {
        return "reload";
    }

    @Override
    public String permission() {
        return "mooncake.reload";
    }

    @Override
    public void onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
        if(BaseUtil.isPlayer(commandSender).booleanValue()){
            commandSender.sendMessage(MoonCake.prefix + "§c该指令只能由控制台使用");
            return;
        }
        (new BukkitRunnable(){
            @Override
            public void run() {
                commandSender.sendMessage(MoonCake.prefix + "§b正在重载配置文件..");
                instance.reloadConfig();
                Bukkit.getServer().clearRecipes();
                RecipeUtil.Ingredient();
                commandSender.sendMessage(MoonCake.prefix + "§a重载成功！");
            }
        }).runTaskAsynchronously(MoonCake.getInstance());
    }
}
